﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>usersol</title>
    <script src="~/lib/axios/dist/axios.js"></script>
    <script src="~/lib/vue/dist/vue.js"></script>
    <script src="~/lib/element-ui/lib/index.js"></script>
    <link href="~/lib/element-ui/lib/theme-chalk/index.css" rel="stylesheet" />
</head>
<body>
    <div id="app">
        <el-container>
            <el-header>
                <el-card class="box-card">
                    <el-col :span="2"> 用户管理 </el-col><el-col :span="6" :offset="21"> 当前角色总数{{total}} </el-col>
                </el-card>
            </el-header>
            <el-main>
                <el-card class="box-card">
                    <el-button type="primary"
                               @@click="dialogVisibleinsert = true"
                               style="float: right; margin-bottom: 20px;">添加</el-button>
                    <el-table :data="list" style="width: 100%" border stripe>
                        <el-table-column prop="u_id"
                                         label="用户编号"
                                         align="center">
                        </el-table-column>
                        <el-table-column prop="u_name"
                                         label="用户名称"
                                         align="center">
                        </el-table-column>
                        <el-table-column prop="u_true_name"
                                         label="真实姓名"
                                         align="center">
                        </el-table-column>
                        <el-table-column prop="u_password"
                                         label="用户密码"
                                         align="center">
                        </el-table-column>
                        <el-table-column prop="Rolename"
                                         label="用户身份"
                                         align="center">
                        </el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button size="mini" type="primary" @@click="sho(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @@click="delt(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <el-row>
                        <el-col :span="1">
                            <el-pagination v-on:size-change="handleSizeChange"
                                           v-on:current-change="handleCurrentChange"
                                           :current-page="queryinfo.currentPage"
                                           :page-sizes="[1, 2, 3, 4]"
                                           :page-size="queryinfo.pageSize"
                                           layout="total, sizes, prev, pager, next, jumper"
                                           :total="total">
                            </el-pagination>
                        </el-col>
                    </el-row>
                </el-card>
            </el-main>
        </el-container>

        <el-dialog title="用户修改"
                   :visible.sync="dialogVisibleUpdate"
                   width="50%">
            <el-form ref="formUpdate"
                     :model="formUpdate"
                     :rules="formruleUpdate"
                     label-width="80px">
                <el-form-item label="用户名称" prop="u_name">
                    <el-input v-model="formUpdate.u_name"></el-input>
                </el-form-item>
                <el-form-item label="真实姓名" prop="u_true_name">
                    <el-input v-model="formUpdate.u_true_name"></el-input>
                </el-form-item>
                <el-form-item label="用户密码" prop="u_password" show-password>
                    <el-input v-model="formUpdate.u_password"></el-input>
                </el-form-item>
                <el-form-item label="用户身份" prop="RoleID">
                    <template>
                        <el-select v-model="formUpdate.RoleID" placeholder="请选择职位" style="width: 100% ">
                            <el-option v-for="item in list1"
                                       :key="item.RoleID"
                                       :label="item.Rolename"
                                       :value="item.RoleID">
                            </el-option>
                        </el-select>
                    </template>
                </el-form-item>
            </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @@click="dialogVisibleUpdate = false">取 消</el-button>
                    <el-button type="primary" @@click="upda('formUpdate')">确 定</el-button>
                </span>
        </el-dialog>

        <el-dialog title="用户添加"
                   :visible.sync="dialogVisibleinsert"
                   width="50%">
            <el-form ref="forminsert"
                     :model="forminsert"
                     :rules="formruleinsert"
                     label-width="80px">
                <el-form-item label="用户名称" prop="u_name">
                    <el-input v-model="forminsert.u_name"></el-input>
                </el-form-item>
                <el-form-item label="真实姓名" prop="u_true_name">
                    <el-input v-model="forminsert.u_true_name"></el-input>
                </el-form-item>
                <el-form-item label="用户密码" prop="u_password" show-password>
                    <el-input v-model="forminsert.u_password"></el-input>
                </el-form-item>
                <el-form-item label="用户身份" prop="Rolename">
                    <template>
                        <el-select v-model="forminsert.Rolename" placeholder="请选择职位" style="width: 100% ">
                            <el-option v-for="item in list1"
                                       :key="item.RoleID"
                                       :label="item.Rolename"
                                       :value="item.RoleID">
                            </el-option>
                        </el-select>
                    </template>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @@click="dialogVisibleinsert = false">取 消</el-button>
                <el-button type="primary" @@click="submitForm('forminsert')">确 定</el-button>
            </span>
        </el-dialog>
    </div>
    <script type="text/javascript">
        var vm = new Vue({
            el: "#app",
            data: {
                list: [],//角色
                list1: [],//职位
                queryinfo: {
                    currentPage: 1,//当前页
                    pageSize: 3//总页数
                },
                total: 1,//总条数
                dialogVisibleUpdate: false,//修改模态框
                formUpdate: {
                    u_name: "",
                    u_true_name: "",
                    u_password: "",
                    RoleID: "",
                    u_id:'',
                },
                formruleUpdate: {
                    RoleID: [
                        { required: true, message: '请选择职位', trigger: 'change' }
                    ],
                    u_name: [
                        { required: true, message: '请填写账号名称', trigger: 'blur' },
                    ],
                    u_true_name: [
                        { required: true, message: '请填写密码', trigger: 'blur' },
                    ],
                    u_password: [
                        { required: true, message: '请填写真实姓名', trigger: 'blur' },
                    ]
                },
                dialogVisibleinsert: false,//添加模态框
                forminsert: {
                    u_name: "",
                    u_true_name: "",
                    u_password: "",
                    Rolename: "",
                },
                formruleinsert: {
                    Rolename: [
                        { required: true, message: '请选择职位', trigger: 'change' }
                    ],
                    u_name: [
                        { required: true, message: '请填写账号名称', trigger: 'blur' },
                    ],
                    u_true_name: [
                        { required: true, message: '请填写密码', trigger: 'blur' },
                    ],
                    u_password: [
                        { required: true, message: '请填写真实姓名', trigger: 'blur' },
                    ]
                }
            },
            methods: {
                delt(row) {
                    this.$confirm('此操作将删除用户, 是否删除?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //角色删除
                        axios.get('/usersol/Delt', {
                            params: {
                                u_id: row.u_id
                            }
                        })
                            .then(res => {
                                console.info(res);
                                this.$message({
                                    type: 'success',
                                    message: '删除成功!'
                                });
                                this.fill();
                            })
                            .catch(err => {
                                console.info(err);
                            });
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                },
                upda(formName) {
                    //表单验证
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                            this.$confirm('此操作将修改用户, 是否修改?', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            }).then(() => {
                                this.update();
                            }).catch(() => {
                                this.$message({
                                    type: 'info',
                                    message: '已取消修改'
                                });
                            });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '请填写完整信息!'
                            });
                            return false;
                        }
                    });
                },
                update() {
                    //角色修改
                    axios.get('/usersol/Update', {
                        params: {
                            u_name: this.formUpdate.u_name,
                            u_true_name: this.formUpdate.u_true_name,
                            u_password: this.formUpdate.u_password,
                            RoleID: this.formUpdate.RoleID,
                            u_id: this.formUpdate.u_id
                        }
                    })
                        .then(res => {
                            console.info(res);
                            this.$message({
                                type: 'success',
                                message: '修改成功!'
                            });
                            this.dialogVisibleUpdate = false;
                            this.fill();
                        })
                        .catch(err => {
                            console.info(err);
                        });
                },
                //修改回显
                sho(row) {
                    this.dialogVisibleUpdate = true;
                    this.formUpdate.u_name = row.u_name;
                    this.formUpdate.u_true_name = row.u_true_name;
                    this.formUpdate.u_password = row.u_password;
                    this.formUpdate.RoleID = row.RoleID;
                    this.formUpdate.u_id = row.u_id;
                },
                submitForm(formName) {
                    //表单验证
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                            this.$confirm('此操作将添加用户, 是否添加?', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            }).then(() => {
                                this.insert();
                            }).catch(() => {
                                this.$message({
                                    type: 'info',
                                    message: '已取消添加'
                                });
                            });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '请填写完整信息!'
                            });
                            return false;
                        }
                    });
                },
                insert() {
                    //角色添加
                    axios.get('/usersol/Insert', {
                        params: {
                            u_name: this.forminsert.u_name,
                            u_true_name: this.forminsert.u_true_name,
                            u_password: this.forminsert.u_password,
                            RoleID: this.forminsert.Rolename
                        }
                    })
                        .then(res => {
                            console.info(res);
                            this.$message({
                                type: 'success',
                                message: '添加成功!'
                            });
                            this.dialogVisibleinsert = false;
                            this.fill();
                        })
                        .catch(err => {
                            console.info(err);
                        });
                },
                fill() {
                    //角色查询
                    axios.get('/usersol/usersols', {
                        params: {
                            currentPage: this.queryinfo.currentPage,
                            pageSize: this.queryinfo.pageSize
                        }
                    })
                        .then(res => {
                            console.info(res);
                            this.list = res.data.Data;
                            this.total = res.data.Row;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                    //可用职位查询
                    axios.get('/usersol/vs')
                        .then(res => {
                            console.info(res);
                            this.list1 = res.data;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                },
                //分页总页数改变事件
                handleSizeChange(val) {
                    this.queryinfo.pageSize = val;
                    this.fill();
                },
                //分页当前页改变事件
                handleCurrentChange(val) {
                    this.queryinfo.currentPage = val;
                    this.fill();
                }
            },
            //可以对vue的数据和方法进行操作,不能对DOM进行操作
            created: function () {
                this.fill();
            }
        });
    </script>
    <style scoped>

        .el-col-2 {
            width: 8.33333%;
            font-size: 15px;
            font-weight: 900;
            line-height: 0px;
        }

        .el-col-6 {
            width: 37.5%;
            font-size: 1px;
            font-weight: 300;
            line-height: 0px;
            color: rgb(83, 83, 83);
        }

        element.style {
            height: 100%;
            width: 1239px;
        }
        .el-card__body {
            padding: 35px;
        }
        .el-button.is-circle {
            border-radius: 50%;
            padding: 12px;
            position: relative;
            top: -10px;
            right: -570px;
        }
    </style>
</body>
</html>
